{# Copyright The IETF Trust 2015-2022, All Rights Reserved #}
{% load origin %}
{% load static %}
{% load textfilters tz %}
{% load ietf_filters session_filters %}

{% origin %}
{% if item and item|should_show_agenda_session_buttons %}
    {% with slug=item.slug session=item.session timeslot=item.timeslot %}
        {% if session.agenda and show_agenda %}
            {# Note: if called with show_agenda=True, calling template must load agenda_materials.js, needed by session_agenda_include.html #}
            {% include "meeting/session_agenda_include.html" with slug=slug session=session timeslot=timeslot only %}
        {% endif %}
        <div id="session-buttons-{{ session.pk }}"
            role="group"
            class="btn-group btn-group-sm d-none d-lg-flex">
            {% with acronym=session.group_at_the_time.acronym %}
                {% if session.agenda and show_agenda %}
                    {# agenda pop-up button #}
                    <button class="btn btn-outline-primary"
                            data-bs-toggle="modal" type="button"
                            data-bs-target="#modal-{{ slug }}"
                            aria-label="Show meeting materials"
                            title="Show meeting materials">
                        <i class="bi bi-arrows-fullscreen"></i>
                    </button>
                    {# materials tar file #}
                    <a class="btn btn-outline-primary"
                        role="button"
                        href="/meeting/{{ meeting.number }}/agenda/{{ acronym }}-drafts.tgz"
                        aria-label="Download meeting materials as .tar archive"
                        title="Download meeting materials as .tar archive">
                        <i class="bi bi-file-zip"></i>
                    </a>
                    {# materials PDF file #}
                    <a class="btn btn-outline-primary"
                        role="button"
                        href="/meeting/{{ meeting.number }}/agenda/{{ acronym }}-drafts.pdf"
                        aria-label="Download meeting materials as PDF file"
                        title="Download meeting materials as PDF file">
                        <i class="bi bi-file-pdf"></i>
                    </a>
                {% endif %}
                {# Notes #}
                {% if meeting.uses_notes %}
                    <a class="btn btn-outline-primary"
                        role="button"
                        href="{{ session.notes_url }}"
                        aria-label="Notepad for note-takers"
                        title="Notepad for note-takers">
                        <i class="bi bi-journal-text"></i>
                    </a>
                {% endif %}
                {# show stream buttons up till end of session, then show archive buttons #}
                {% if timezone_now < timeslot.end_time %}
                    {# chat #}
                    <a class="btn btn-outline-primary"
                        role="button"
                        href="{{ session.chat_room_url }}"
                        aria-label="Chat room for {{ session.chat_room_name }}"
                        title="Chat room for {{ session.chat_room_name }}">
                        <i class="bi bi-chat"></i>
                    </a>
                    {# Video stream (meetecho) #}
                    {% if session.video_stream_url %}
                        <a class="btn btn-outline-primary"
                            role="button"
                            href="{{ session.video_stream_url }}"
                            aria-label="Video stream"
                            title="Video stream">
                            <i class="bi bi-camera-video"></i>
                        </a>
                    {% endif %}
                    {# Onsite tool (meetecho_onsite) #}
                    {% if session.onsite_tool_url %}
                        <a class="btn btn-outline-primary"
                            role="button"
                            href="{{ session.onsite_tool_url }}"
                            aria-label="Onsite tool"
                            title="Onsite tool">
                            <i class="bi bi-phone"></i>
                        </a>
                    {% endif %}
                    {# Audio stream #}
                    {% if session.audio_stream_url %}
                        <a class="btn btn-outline-primary"
                            role="button"
                            href="{{ session.audio_stream_url }}"
                            aria-label="Audio stream"
                            title="Audio stream">
                            <i class="bi bi-headphones"></i>
                        </a>
                    {% endif %}
                    {# Remote call-in #}
                    {% if session.agenda_note|first_url|conference_url %}
                        <a class="btn btn-outline-primary"
                            role="button"
                            href="{{ session.agenda_note|first_url }}"
                            aria-label="Online conference"
                            title="Online conference">
                            <i class="bi bi-people"></i>
                        </a>
                    {% elif session.remote_instructions|first_url|conference_url %}
                        <a class="btn btn-outline-primary"
                            role="button"
                            href="{{ session.remote_instructions|first_url }}"
                            aria-label="Online conference"
                            title="Online conference">
                            <i class="bi bi-people"></i>
                        </a>
                    {% elif timeslot.location.webex_url %}
                        <a class="btn btn-outline-primary"
                            role="button"
                            href="{{ timeslot.location.webex_url|format:session }}"
                            aria-label="Webex session"
                            title="Webex session">
                            <i class="bi bi-people"></i>
                        </a>
                    {% endif %}
                    {# iCalendar item #}
                    <a class="btn btn-outline-primary"
                        role="button"
                        href="{% url 'ietf.meeting.views.agenda_ical' num=meeting.number session_id=session.id %}"
                        aria-label="icalendar entry for {{ acronym }} session on {{ timeslot.time|utc|date:'Y-m-d H:i' }} UTC"
                        title="icalendar entry for {{ acronym }} session on {{ timeslot.time|utc|date:'Y-m-d H:i' }} UTC">
                        <i class="bi bi-calendar"></i>
                    </a>
                {% else %}
                    {# chat logs #}
                    {% if meeting.has_chat_logs and session.chatlog %}
                        <a class="btn btn-outline-primary"
                            role="button"
                            href="/doc/{{ session.chatlog.document.name }}"
                            aria-label="Chat logs for {{ session.chat_room_name }}"
                            title="Chat logs for {{ session.chat_room_name }}">
                            <i class="bi bi-file-text"></i>
                        </a>
                    {% endif %}
                    {# Recordings #}
		    {% if meeting.has_recordings %}
                        {% with session.recordings as recordings %}
                            {% if recordings %}
                                {# There's no guaranteed order, so this is a bit messy: #}
                                {# First, the audio recordings, if any #}
                                {% for r in recordings %}
                                    {% if r.get_href and 'audio' in r.get_href %}
                                        <a class="btn btn-outline-primary"
                                            role="button"
                                            href="{{ r.get_href }}"
                                            aria-label="{{ r.title }}"
                                            title="{{ r.title }}">
                                            <i class="bi bi-file-play"></i>
                                        </a>
                                    {% endif %}
                                {% endfor %}
                                {# Then the youtube recordings #}
                                {% for r in recordings %}
                                    {% if r.get_href and 'youtu' in r.get_href %}
                                        <a class="btn btn-outline-primary"
                                            role="button"
                                            href="{{ r.get_href }}"
                                            aria-label="{{ r.title }}"
                                            title="{{ r.title }}">
                                            <i class="bi bi-file-slides"></i>
                                        </a>
                                    {% endif %}
                                {% endfor %}
                                {# Finally, any other recordings #}
                                {% for r in recordings %}
                                    {% if r.get_href and not 'audio' in r.get_href and not 'youtu' in r.get_href %}
                                        <a class="btn btn-outline-primary"
                                            role="button"
                                            href="{{ r.get_href }}"
                                            aria-label="{{ r.title }}"
                                            title="{{ r.title }}">
                                            <i class="bi bi-file-play"></i>
                                        </a>
                                    {% endif %}
                                {% endfor %}
                            {% endif %}
                        {% endwith %}
                        {% if session.video_stream_url %}
                            <a class="btn btn-outline-primary"
                                role="button"
                                href="{{ session.session_recording_url }}"
                                aria-label="Session recording"
                                title="Session recording">
                                <i class="bi bi-file-slides"></i>
                            </a>
                        {% endif %}
                    {% endif %}
                {% endif %}
            {% endwith %}
        </div>
        <div class="dropdown d-lg-none">
            <button class="btn btn-outline-primary btn-sm dropdown-toggle"
                    type="button"
                    aria-label="Info"
                    id="session-buttons-dropdown-{{ session.pk }}"
                    data-bs-toggle="dropdown"
                    aria-haspopup="true"
                    aria-expanded="false">
                <i class="bi bi-info-lg"></i>
            </button>
            <ul class="dropdown-menu"
                aria-labelledby="session-buttons-dropdown-{{ session.pk }}">
                {% with acronym=session.group_at_the_time.acronym %}
                    {% if session.agenda and show_agenda %}
                        {# agenda pop-up button #}
                        <li>
                            <button class="dropdown-item" type="button"
                                    data-bs-toggle="modal"
                                    data-bs-target="#modal-{{ slug }}">
                                <i class="bi bi-arrows-fullscreen"></i> Show meeting materials
                            </button>
                        </li>
                        {# materials tar file #}
                        <li>
                            <a class="dropdown-item"
                                href="/meeting/{{ meeting.number }}/agenda/{{ acronym }}-drafts.tgz">
                                <i class="bi bi-file-zip"></i> Meeting materials archive
                            </a>
                        </li>
                        {# materials PDF file #}
                        <li>
                            <a class="dropdown-item"
                                href="/meeting/{{ meeting.number }}/agenda/{{ acronym }}-drafts.pdf">
                                <i class="bi bi-file-pdf"></i> Meeting materials PDF
                            </a>
                        </li>
                    {% endif %}
                    {# Notes #}
                    {% if meeting.uses_notes %}
                        <li>
                            <a class="dropdown-item" href="{{ session.notes_url }}">
                                <i class="bi bi-journal-text"></i> Notepad for note-takers
                            </a>
                        </li>
                    {% endif %}
                    {# show stream buttons up till end of session, then show archive buttons #}
                    {% if timezone_now < timeslot.end_time %}
                        {# chat #}
                        <li>
                            <a class="dropdown-item"
                                href="{{session.chat_room_url}}">
                                <i class="bi bi-chat"></i> Chat room
                            </a>
                        </li>
                        {# Video stream (meetecho) #}
                        {% if session.video_stream_url %}
                            <li>
                                <a class="dropdown-item"
                                    href="{{ session.video_stream_url }}">
                                    <i class="bi bi-camera-video"></i> Video stream
                                </a>
                            </li>
                        {% endif %}
                        {# Onsite tool (meetecho_onsite) #}
                        {% if session.onsite_tool_url %}
                        <li>
                            <a class="dropdown-item"
                                href="{{ session.onsite_tool_url }}">
                                <i class="bi bi-phone"></i> Onsite tool
                            </a>
                        </li>
                        {% endif %}
                        {# Audio stream #}
                        {% if session.audio_stream_url %}
                            <li>
                                <a class="dropdown-item"
                                    href="{{ session.audio_stream_url }}">
                                    <i class="bi bi-headphones"></i> Audio stream
                                </a>
                            </li>
                        {% endif %}
                        {# Remote call-in #}
                        {% if session.agenda_note|first_url|conference_url %}
                            <li>
                                <a class="dropdown-item" href="{{ session.agenda_note|first_url }}">
                                    <i class="bi bi-people"></i> Online conference
                                </a>
                            </li>
                        {% elif session.remote_instructions|first_url|conference_url %}
                            <li>
                                <a class="dropdown-item"
                                    href="{{ session.remote_instructions|first_url }}">
                                    <i class="bi bi-people"></i> Online conference
                                </a>
                            </li>
                        {% elif timeslot.location.webex_url %}
                            <li>
                                <a class="dropdown-item"
                                    href="{{ timeslot.location.webex_url|format:session }}">
                                    <i class="bi bi-people"></i> Webex session
                                </a>
                            </li>
                        {% endif %}
                        {# iCalendar item #}
                        <li>
                            <a class="dropdown-item"
                                href="{% url 'ietf.meeting.views.agenda_ical' num=meeting.number session_id=session.id %}">
                                <i class="bi bi-calendar"></i> Add to calendar
                            </a>
                        </li>
                    {% else %}
                        {# chat logs #}
			            {% if meeting.has_chat_logs and session.chatlog %}
                            <li>
                                <a class="dropdown-item"
                                    href="/doc/{{ session.chatlog.document.name }}">
                                    <i class="bi bi-file-text"></i> Chat logs
                                </a>
                            </li>
                        {% endif %}
                        {# Recordings #}
                        {% if meeting.has_recordings %}
                            {% with session.recordings as recordings %}
                                {% if recordings %}
                                    {# There's no guaranteed order, so this is a bit messy: #}
                                    {# First, the audio recordings, if any #}
                                    {% for r in recordings %}
                                        {% if r.get_href and 'audio' in r.get_href %}
                                            <li>
                                                <a class="dropdown-item" href="{{ r.get_href }}">
                                                    <i class="bi bi-file-play"></i> {{ r.title }}
                                                </a>
                                            </li>
                                        {% endif %}
                                    {% endfor %}
                                    {# Then the youtube recordings #}
                                    {% for r in recordings %}
                                        {% if r.get_href and 'youtu' in r.get_href %}
                                            <li>
                                                <a class="dropdown-item" href="{{ r.get_href }}">
                                                    <i class="bi bi-file-slides"></i> {{ r.title }}
                                                </a>
                                            </li>
                                        {% endif %}
                                    {% endfor %}
                                    {# Finally, any other recordings #}
                                    {% for r in recordings %}
                                        {% if r.get_href and not 'audio' in r.get_href and not 'youtu' in r.get_href %}
                                            <li>
                                                <a class="dropdown-item" href="{{ r.get_href }}">
                                                    <i class="bi bi-file-play"></i> {{ r.title }}
                                                </a>
                                            </li>
                                        {% endif %}
                                    {% endfor %}
                                {% endif %}
                            {% endwith %}
                            {% if session.video_stream_url %}
                                <li>
                                    <a class="dropdown-item"
                                        href="{{ session.session_recording_url }}">
                                        <i class="bi bi-file-slides"></i> Session recording
                                    </a>
                                </li>
                            {% endif %}
                        {% endif %}
                    {% endif %}
                {% endwith %}
            </ul>
        </div>
    {% endwith %}
{% endif %}
